﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using C.Entities;

namespace C.Unite
{
    /// <summary>
    /// 数据缓存
    /// </summary>
    public class DBCaChe
    {
        #region 缓存数据重载
        /// <summary>
        /// 重载缓存权限数据
        /// </summary>
        /// <returns></returns>
        public static void ReLoadPerList()
        {
            List<Sys_PerInfo> perinfo = new List<Sys_PerInfo>();
            if (CacheHelper.ExistIdentify("PerList"))
            {
                CacheHelper.RemoveIdentify("PerList");
                perinfo = TbsDbSession.Default.From<Sys_PerInfo>().ToList();
                CacheHelper.InsertIdentify("PerList", perinfo, 1, 2);
            }
        }
        /// <summary>
        /// 重载缓存模块数据
        /// </summary>
        public static void RefreshModelsList()
        {
            if (CacheHelper.ExistIdentify("ModelList"))
            {
                CacheHelper.RemoveIdentify("ModelList");
                GetModelList();
            }
        }
        #endregion

        #region 泛型实例缓存区
        /// <summary>
        /// 取得权限缓存数据
        /// </summary>
        /// <returns></returns>
        public static List<Sys_PerInfo> GetPerList()
        {
            List<Sys_PerInfo> perinfo = new List<Sys_PerInfo>();
            if (!CacheHelper.ExistIdentify("PerList"))
            {
                perinfo = TbsDbSession.Default.From<Sys_PerInfo>().ToList();
                CacheHelper.InsertIdentify("PerList", perinfo, 1, 2);
            }
            else
            {
                perinfo = (List<Sys_PerInfo>)CacheHelper.ReadIdentify("PerList");
            }
            return perinfo;
        }

        /// <summary>
        /// 缓存模块
        /// </summary>
        /// <returns></returns>
        public static List<Sys_Modules> GetModelList()
        {

            List<Sys_Modules> modulesinfo = new List<Sys_Modules>();
            if (!CacheHelper.ExistIdentify("ModelList"))
            {
                modulesinfo = TbsDbSession.Default.From<Sys_Modules>().OrderBy(Sys_Modules._.Orderid.Asc, Sys_Modules._.Mid.Desc).ToList();
                CacheHelper.InsertIdentify("ModelList", modulesinfo, 1, 2);
            }
            else
            {
                modulesinfo = (List<Sys_Modules>)CacheHelper.ReadIdentify("ModelList");
            }
            return modulesinfo;
        }
        #endregion
    }
}